package test;


import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import org.junit.Test;


import java.io.IOException;
import java.io.InputStream;
import java.sql.*;
import java.util.Properties;

public class HikariCP {
    public  static HikariDataSource ds;
    @Test
    public void hikaricp(){
        try {
            if (ds==null) {
                InputStream in = HikariCP.class.getClassLoader().getResourceAsStream("src/hikaricp.properties");
                Properties properties = new Properties();
                properties.load(in);
                HikariConfig config=new HikariConfig(properties);
                ds=new HikariDataSource(config);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        Connection connection=null;
        PreparedStatement statement=null;
        ResultSet resultSet=null;
        //创建连接
        try {
            connection=ds.getConnection();
            statement=connection.prepareStatement("select *from student");
            resultSet=statement.executeQuery();
            while (resultSet.next()){
                System.out.println(resultSet.getInt("id")+"--"+resultSet.getString("name")+"--"+resultSet.getInt("age"));
            }
            connection.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
